<?php
/**
 *
 * @author Zhang Di <zhangdi_me@163.com>
 */


namespace yiiwiki\ping;

use Yii;
use yii\log\Logger;

class Baidu extends Client implements Pingable
{
    public $serverUrl = 'http://ping.baidu.com/ping/RPC2';

    public function ping($siteName, $homepage, $url, $rss, $encoding = "UTF-8")
    {
        $data = [$siteName, $homepage, $url, $rss];
        $request = xmlrpc_encode_request(
            'weblogUpdates.extendedPing',
            $data,
            ['encoding' => $encoding]
        );
        $response = $this->post($this->serverUrl, $request);
        Yii::getLogger()->log('Ping Baidu Data: ' . print_r($data, true), Logger::LEVEL_INFO, 'yiiwiki-ping');
        Yii::getLogger()->log('Ping Baidu Response: ' . $response, Logger::LEVEL_INFO, 'yiiwiki-ping');
        $result = strpos($response, "<int>0</int>") ? true : false;
        if ($result) {
            Yii::getLogger()->log('Ping Baidu 成功.', Logger::LEVEL_INFO, 'yiiwiki-ping');
        } else {
            Yii::getLogger()->log('Ping Baidu 失败.', Logger::LEVEL_INFO, 'yiiwiki-ping');
        }
    }

} 